package tgc.edu.yzy.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name="yzy_student")
public class Student {
	
	private Integer id;
	private String name;//姓名
	private Integer age;//年龄
	private String gender;//性别
	private String number;//联系电话
	private String sn;//学号 student number 缩写
	private String password;//登陆密码
	private Bj bj;//班级的字段
	private List<Grade> grade=new ArrayList<Grade>();//一对多 一个学生对应多个课程的成绩
	private List<Teacher> teacher=new ArrayList<Teacher>();
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	
	@Column(length=20)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@Column(length=20)
	public Integer getAge() {
		return age;
	}
	public void setAge(Integer age) {
		this.age = age;
	}
	
	@Column(length=20)
	public String getGender() {
		return gender;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	
	@Column(length=30)
	public String getNumber() {
		return number;
	}
	public void setNumber(String number) {
		this.number = number;
	}
	
	@Column(length=20,nullable=false,unique=true)
	public String getSn() {
		return sn;
	}
	public void setSn(String sn) {
		this.sn = sn;
	}
	
	@Column(length=20)
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	@ManyToOne
	public Bj getBj() {
		return bj;
	}
	public void setBj(Bj bj) {
		this.bj = bj;
	}
	
	@OneToMany(cascade=CascadeType.ALL,mappedBy="student")
	public List<Grade> getGrade() {
		return grade;
	}
	public void setGrade(List<Grade> grade) {
		this.grade = grade;
	}
	//非持久化
	@Transient
	public List<Teacher> getTeacher(){//teacher 课程 grade 成绩
		List<Teacher> teacher=new ArrayList<>();
		for(Grade grade:getGrade()) {
			teacher.add(grade.getTeacher());
		}
		return teacher;
	}
	
	@Transient
	public String getTeachername() {
		String str="";
		for(Teacher t:getTeacher()) {
			str+=t.getCourse()+"("+t.getTcname()+"任)"+"\r\r";
		}
		if(str.length()>0) {
			str=str.substring(0,str.length()-1);
		}
		return str;
	}
	@Transient
	public String getTeacherone() {
		String str="";
		for(Teacher t:getTeacher()) {
			str+=t.getCourse()+"、";
		}
		if(str.length()>0) {
			str=str.substring(0,str.length()-1);
		}
		return str;
	}
	public Student(Integer id, String name, Integer age, String gender, String number, String sn, String password,
			Bj bj, List<Grade> grade, List<Teacher> teacher) {
		super();
		this.id = id;
		this.name = name;
		this.age = age;
		this.gender = gender;
		this.number = number;
		this.sn = sn;
		this.password = password;
		this.bj = bj;
		this.grade = grade;
		this.teacher = teacher;
	}
	public Student(String name, Integer age, String gender, String number, String sn, String password, Bj bj,
			List<Grade> grade, List<Teacher> teacher) {
		super();
		this.name = name;
		this.age = age;
		this.gender = gender;
		this.number = number;
		this.sn = sn;
		this.password = password;
		this.bj = bj;
		this.grade = grade;
		this.teacher = teacher;
	}
	public Student(String name, Integer age, String gender, String number, String sn, String password) {
		super();
		this.name = name;
		this.age = age;
		this.gender = gender;
		this.number = number;
		this.sn = sn;
		this.password = password;
	}
	public Student(Integer id, String name, Integer age, String gender, String number, String sn, String password) {
		super();
		this.id = id;
		this.name = name;
		this.age = age;
		this.gender = gender;
		this.number = number;
		this.sn = sn;
		this.password = password;
	}
	public Student() {
		super();
		// TODO Auto-generated constructor stub
	}
	public Student(Integer id) {
		super();
		this.id = id;
	}
	
	
	
}
